/**
 * 商品详情页
 */
const { router, libQuery } = require('../../lib/route')

libQuery((req, res, next, method) => {
  const params = req.params || {}
  const id = params.id || 0
  if (id === 0) {
    console.log('params=', res.params)
    res.send(JSON.stringify({}))
    return
  }

  const dataPath = '../datas/spu/' + id + '.js'
  console.log('/spu ->> dataPath=', dataPath)
  const data = require(dataPath)

  if (data) {
    setTimeout(() => {
      res.send(JSON.stringify(data))
    }, 1000);
  } else {
    res.renderError('没有找到 ' + dataPath)
  }
}, '/spu/:id')

module.exports = router